import Vue from 'vue'

import 'normalize.css/normalize.css' // A modern alternative to CSS resets

import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
// import locale from 'element-ui/lib/locale/lang/en' // lang i18n

import '@/styles/index.scss' // global css

import App from './App'
import store from './store'
import router from './router'

import '@/icons' // icon
import '@/permission' // permission control
// 直接导入并执行指令
// import '@/directives'
// 2. 按需注册指令
// import { red, imgerror } from '@/directives/index'
// Vue.directive('red', red)
// Vue.directive('imgerror', imgerror)
import * as allDriectives from '@/directives'
import * as allFilters from '@/filter'
import MyComponent from '@/components/index'
Object.keys(allFilters).forEach(k => {
  Vue.filter(k, allFilters[k])
})
Vue.use(MyComponent)
// console.log(allDriectives) // 是一个对象包含所有的指令
// 循环遍历 对象 批量注册
// for (const k in allDriectives) {
//   Vue.directive(k, allDriectives[k]) // k 键 allDriectives[k] 值
// }
Object.keys(allDriectives).forEach(k => { // 对象的键收集到的数组
  Vue.directive(k, allDriectives[k])
})

// set ElementUI lang to EN
// Vue.use(ElementUI, { locale })
// 如果想要中文版 element-ui，按如下方式声明
Vue.use(ElementUI)

Vue.config.productionTip = false

new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
